const express = require('express')
const route = express.Router()
const adminModel = require('../db/model/adminModel')
//引入权限校验中间件
const isLoginMiddle = require("../middleware/isLoginMiddle")

//引入jwt模块
const { jwtDecode } = require('../utils/jwt')

route.get('/logout', isLoginMiddle, async (req, res) => {
  const { token } = req.headers
  const { adminName } = jwtDecode(token, '666')
  try {
    await adminModel.updateOne({ adminName }, {
      $set: {
        status: 0
      }
    })
    return res.send({
      code: 10000,
      msg: "退出登录成功",
      data: null
    })

  } catch (e) {
    console.log("退出登录出现异常" + e.message);
    res.send({
      code: 10001,
      msg: "退出登录出现异常" + e.message,
      data: null
    })
  }
})

module.exports = route